package com.xiaobawang.xjsyy_idea_plugin.panel.config.view;

import com.dtflys.forest.Forest;
import com.intellij.openapi.ui.ComboBox;
import com.xiaobawang.xjsyy_idea_plugin.forest.ForestApi;
import com.xiaobawang.xjsyy_idea_plugin.global.GlobalConfig;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;
import java.util.Map;

/**
 * @author synhard
 * @description TODO
 * @date 2024/5/23 13:35
 * @email songxinhang2023@e-chinalife.com
 * @id 18101119
 * @phone 13001321080
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class OrgSelectPanel extends JPanel {

    JComboBox<String> comboBox;

    private static final Logger logger = LoggerFactory.getLogger(OrgSelectPanel.class);

    public OrgSelectPanel() {
        this.setLayout(new FlowLayout());
        add(new JLabel("选择企业: "));
        // 创建一个 ComboBox 实例
        this.comboBox = new ComboBox<>();

        // 添加选项到下拉框
        for (Map.Entry<String, String> entry : GlobalConfig.org2Id.entrySet()) {
            comboBox.addItem(entry.getKey());
            comboBox.setSelectedItem(GlobalConfig.id2Org.get(GlobalConfig.curOrgId));
        }

        // 添加一个动作监听器，以打印用户选择的选项
        this.comboBox.addActionListener(e -> {
            String selected = (String) comboBox.getSelectedItem();
            GlobalConfig.curOrgId = GlobalConfig.org2Id.get(selected);
        });

        add(this.comboBox);
    }
}
